const express = require('express');
import { Router, Request, Response} from "express";
const userRoute: Router = express.Router();
let userList: Array<any> = [];

userRoute.get('/userList', (req: Request, res: Response) => {
  let lists = [
    {
      name: 'zhangsan',
      age: 11
    },
    {
      name: 'zhangsan2',
      age: 12
    },
    {
      name: 'zhangsan3',
      age: 32
    }
  ]
  res.send(lists);
});

userRoute.post('/postParams', (req: Request, res: Response) => {
  // name=postman&age=56&color=red
  req.body.name && userList.push(req.body);
  res.send(userList);
});

userRoute.get('/listTpl', (req: Request, res: Response) => {
  res.render('one', { users: userList });
});

module.exports = userRoute;
